<template>
  <div class="innerPageTable-box-OneTwo innerPageTable-out-flex">
     <!-- 搜索区域 -->
    <SelfAdaption>
      <Form
        :model="searchForm"
        ref="modelForm"
        slot="adaption-bar"
        label-position="top"
        class="ivu-form-no-margin-bottom"
        inline
      >
        <Form-item prop="tenantId" :label="$t('module.tenantManage.tenantID')">
          <Input
            type="text"
            :maxlength="30"
            v-model.trim="searchForm.tenantId"
            placeholder
            @on-enter="search"
          ></Input>
        </Form-item>
        <Form-item prop="tenantName" :label="$t('module.tenantManage.tenantName')">
          <Input
            type="text"
            :maxlength="30"
            v-model.trim="searchForm.tenantName"
            placeholder
            @on-enter="search"
          ></Input>
        </Form-item>
        <Form-item prop="button" class="search-solt-btn">
           <RPButton optType="search" @click="search" />
           <RPButton optType="reset" @click="reset" />
        </Form-item>
      </Form>
    </SelfAdaption>
    <InnerPageTable ref="tenantKeyTable" :config="tableConfig">
      <div slot="table-bar">
        <RPButton optType="create" @click="addModel" />
      </div>
    </InnerPageTable>
  </div>
</template>

<script>
import addKey from './addKey.vue'
import tenantConfig from '../../tenantConfig/tenantConfig.vue'
import { getTenantList, deleteKey } from '@api/flowable/tenantManage.js'
import { tenantKeyColumns } from './columns.js'
// import IframeContainer from '@/components/IframeContainer.vue'
export default {
  name: 'tenant-key',
  // components: { IframeContainer },
  data() {
    return {
      searchForm: {
        tenantName: '',
        tenantId: ''
      },
      tableConfig: {
        loadDataFn: ({ responseProcess, param }) => {
          getTenantList(param).then(({ data }) => {
            data.currentPage = data.pageNum
            delete data.pageNum
            data.recordCount = data.total
            delete data.total

            data.recordList = data.records
            delete data.records
            responseProcess(data)
          })
        },
        columnsFn: tenantKeyColumns.bind(this),
        autoFirst: true,
        loading: false,
        initParam: { state: 1 }
      },
      isFull: false,
      isNav: true
    }
  },
  methods: {
    search() {
      //刷新列表
      this.$refs['tenantKeyTable'].load(this.searchForm)
    },
    reset() {
      this.$refs['modelForm'].resetFields()
      this.search()
    },
    addModel() {
      let keyInfo = {}
      new this.$pageModal(
        addKey,
        {
          props: {
            keyInfo
          }
        },
        data => {
          if (data) {
            this.search()
          }
        }
      )
    },
    editKey(row) {
      let keyInfo = row
      new this.$pageModal(
        addKey,
        {
          props: {
            keyInfo
          }
        },
        data => {
          if (data) {
            this.search()
          }
        }
      )
    },
    _deleteKey(row) {
      new $confirm(this.$t('common.warning.confirmToDelete'), this).then(() => {
        deleteKey({ tenantId: row.tenantId }).then(res => {
          this.$Message.success({
            content: this.$t('common.deleteSuccess'),
            duration: 3
          })
          this.search()
        })
      })
    },
    _config(row) {
      this.sidelip = new this.$sidelipPage(
        tenantConfig,
        {
          props: {
            tenantInfo: row
          },
          full: this.isFull,
          isNav: this.isNav
        },
        () => {
          this.sidelip = null
        },
        this
      )
    }
  }
}
</script>